const key = require('./db')
let JwtStrategy = require('passport-jwt').Strategy,
    ExtractJwt = require('passport-jwt').ExtractJwt;
let opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = key.keyToken;
const mongoose = require('mongoose')
const Person = mongoose.model('modelPerson')
module.exports = passport => {
    passport.use(new JwtStrategy(opts, async (jwt_payload, done) => {
        // console.log(jwt_payload)
        const person = await Person.findById(jwt_payload.id)
        if(person){
            done(null, person)
        }else{
            done(null, false)
        }
    }));
}